<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link href="../../component/pear/css/pear.css" rel="stylesheet"/>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">关键字</label>
                <div class="layui-input-inline">
                    <input type="text" name="keyWord" placeholder="任务名称|备注" class="layui-input">
                </div>
                <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="do-query">
                    <i class="layui-icon layui-icon-search"></i>
                    查询
                </button>
                <button type="reset" class="pear-btn pear-btn-md">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </form>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="table" lay-filter="table-filter"></table>
    </div>
</div>

</body>

<script type="text/html" id="record-toolbar">
    {{#if (d.doStatus == 1) { }}
    <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove">
        <i class="layui-icon layui-icon-delete"></i>
    </button>
    {{# } }}
</script>

<script type="text/html" id="table-toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
        <i class="layui-icon layui-icon-add-1"></i>
        发起任务
    </button>
</script>

<script src="../../component/layui/layui.js"></script>
<script src="../../component/pear/pear.js"></script>
<script>
    layui.use(['table', 'form', 'common', 'easyAdmin'], function () {
        let easyAdmin = layui.easyAdmin;
        let MODULE_PATH = "do";
        let table = layui.table;
        let form = layui.form;
        let common = layui.common;

        let cols = [
                [
                    {
                        title: '任务序号',
                        field: 'doId',
                        align: 'center',
                    },
                    {
                        title: '任务标题',
                        field: 'doTitle',
                        align: 'center',
                    },
                    {
                        title: '任务内容',
                        field: 'doContent',
                        align: 'center',
                    },
                    {
                        title: '最迟完成时间',
                        field: 'lastDate',
                        align: 'center',
                    },
                    {
                        title: '状态',
                        field: 'doStatus',
                        align: 'center',
                        templet: function (d) {
                            if (d.doStatus == 2) {
                                return '<span style="color: #eb7350;">已完成</span>'
                            }
                            return '<span style="color: #00b487;">处理中</span>'
                        }
                    },
                    {
                        title: '操作',
                        toolbar: '#record-toolbar',
                        align: 'center',
                        width: 250
                    }
                ]
            ]
        ;

        easyAdmin.tableRender({
            elem: '#table', // 对应table的id
            url: '/ext/do',
            page: true, // 分页参数可以自定义
            cols: cols, // 列表示
            skin: 'line', // 表格样式
            toolbar: '#table-toolbar', // 表格头部工具栏 可定义左上角和右上角工具栏,一般用于左上角配置
            defaultToolbar: [{  // 自由配置头部工具栏右侧的图标按钮
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports']
        });

        // toolbar: '#toolbarDemo'
        // toolbar 点击头部工具栏区域设定了属性为 lay-event="" 的元素时触发(包括左上角和右上角)
        table.on('toolbar(table-filter)', function (obj) {
            switch (obj.event) {
                case 'add':
                    easyAdmin.JumpAdd(MODULE_PATH);
                    break;
                case 'refresh':
                    easyAdmin.tableRefresh('table');
                    break;
            }
        });

        table.on('tool(table-filter)', function (obj) {
            switch (obj.event) {
                case 'remove':
                    window.remove(obj);
                    break;
            }
        });

        window.remove = function (obj) {
            layer.confirm('确定要删除该任务', {
                icon: 3,
                title: '提示'
            }, function (index) {
                layer.close(index);
                let loading = layer.load();
                easyAdmin.http({
                    url: "/ext/do/" + obj.data['doId'],
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.success) {
                            layer.msg(result.msg, {
                                icon: 1,
                                time: 1000,
                                area: ['100px', '80px'],
                                content: "删除成功"
                            }, function () {
                                obj.del();
                            });
                        } else {
                            layer.msg(result.msg, {
                                icon: 2,
                                time: 1000,
                                area: ['260px', '80px']
                            });
                        }
                    }
                })
            });
        }

        // 触发submit提交 按钮点击或者表单被执行提交时触发
        form.on('submit(do-query)', function (data) {
            table.reload('table', {
                // //设定异步数据接口的额外参数
                where: data.field
            })
            return false; // 阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    })
</script>
</html>
